/*
 *   @Author: 1296
 *   @Date: 2025-03-20
 *   @Description: 实现路由守卫中的用户权限验证
*/

import router from "@/router";

export const getCurrentUser = () => {
    return {
        token: sessionStorage.getItem('userToken'),
        username: sessionStorage.getItem('username')
    }
}

export const validateRouteUser = (routeUser) => {
    const { username } = getCurrentUser()
    return username === routeUser
}


import { validateRouteUser } from '@/utils/auth'

router.beforeEach((to, from, next) => {

    if (to.meta.validateUser && !validateRouteUser(to.params.username)) {
        next('/unAuthorized')
    }
})